<template>
  <!-- <transition name="switch"> -->
  <div class="loading-warp" v-if="loading" :style="{
    backgroundColor: `rgba(255, 255, 255, ${opacity == 0 ? 0 : opacity || 0.3})`
  }">
    <div v-if="props.type == 'global'">
      <div class="nb-spinner"></div>
    </div>
    <div v-else>
      <!-- <el-icon size="50" class="is-loading">
        <Loading />
      </el-icon> -->
      <div class="loader"></div>
      <slot>
        <span>{{ text }}</span>
      </slot>
    </div>
  </div>
  <!-- </transition>
  <transition name="switch"> -->
  <div v-if="!loading && isEmpty" class="empty-img-warp">
    <slot name="icon">
      <!-- <img src="@/assets/not_content.svg" /> -->
      <SvgIcon name="empty" />
    </slot>
    <div class="text">
      <slot> {{ text }}</slot>
    </div>
  </div>
  <!-- </transition> -->
</template>
<script setup>
// import { Loading } from "@element-plus/icons-vue";
const props = defineProps({
  loading: {
    type: Boolean,
    default: true
  },
  isEmpty: {
    type: Boolean,
    default: true
  },
  type: {
    type: String,
    default: ''
  },
  opacity: {
    type: Number,
    default: 0
  },
  text: {
    type: String,
    default: ''
  }
})
</script>
<style lang="less" scoped>
.loading-warp {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  // background-color: #ffffff;
  // background-color: rgba(255, 255, 255, 0.345);

  >div {
    display: flex;
    align-items: center;
    justify-content: center;
    // height         : 100%;
    // width: 100%;
    color: #888;
    // position: absolute;
    text-align: center;
    height: 100%;

    span {
      // margin-left: 10px;
      display: block;
      font-size: 12px;
    }

    i {
      font-size: 24px;
    }

    .nb-spinner {
      width: 50px;
      height: 50px;
      margin: 0;
      background: transparent;
      border-top: 4px solid #888;
      border-right: 4px solid transparent;
      border-radius: 50%;
      animation: 1s spin linear infinite;
    }

    @keyframes spin {
      from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
      }

      to {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
      }
    }
  }
}

.empty-img-warp {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  z-index: 10;
  // background-color: #fff;

  .icon-empty {
    font-size: 80px;
  }

  .text {
    color: #aaa;
    font-size: 14px;
    margin-top: 15px;
  }

  img {
    width: 120px;
  }
}

// .circular {
//   width: 100px;
//   height: 100px;
//   animation: rotate 2s linear infinite;
//   margin: auto;

//   .path {
//     stroke-dasharray: 1, 200;
//     stroke-dashoffset: 0;
//     stroke: #aaa;
//     animation: dash 1.5s ease-in-out infinite;
//   }
// }

// @keyframes rotate {
//   100% {
//     transform: rotate(360deg);
//   }
// }

// @keyframes dash {
//   0% {
//     stroke-dasharray: 1, 200;
//     stroke-dashoffset: 0;
//   }

//   50% {
//     stroke-dasharray: 89, 200;
//     stroke-dashoffset: -35px;
//   }

//   100% {
//     stroke-dasharray: 89, 200;
//     stroke-dashoffset: -124px;
//   }
// }

.loader {
  width: 20px;
  padding: 3px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #aaa;
  --_m: conic-gradient(#0000 10%, #000), linear-gradient(#000 0 0) content-box;
  -webkit-mask: var(--_m);
  mask: var(--_m);
  -webkit-mask-composite: source-out;
  mask-composite: subtract;
  animation: l3 1s infinite linear;
}

@keyframes l3 {
  to {
    transform: rotate(1turn);
  }
}
</style>
